package com.ibm.risk.irmp.workflow.client.flowable.api;

import com.ibm.risk.irmp.workflow.client.flowable.ApiClient;

import com.ibm.risk.irmp.workflow.client.flowable.model.DataResponseHistoricPlanItemInstanceResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.HistoricPlanItemInstanceQueryRequest;
import com.ibm.risk.irmp.workflow.client.flowable.model.HistoricPlanItemInstanceResponse;
import java.time.OffsetDateTime;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;


@Component("com.ibm.risk.irmp.flowable.api.HistoryPlanItemApi")
public class HistoryPlanItemApi {
    private ApiClient apiClient;

    public HistoryPlanItemApi() {
        this(new ApiClient());
    }

    @Autowired
    public HistoryPlanItemApi(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return apiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    /**
     * Get a historic plan item instance
     *
     * <p><b>200</b> - Indicates that the historic plan item instances could be found.
     * <p><b>404</b> - Indicates that the historic plan item instances could not be found.
     * @param planItemInstanceId The planItemInstanceId parameter
     * @return HistoricPlanItemInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public HistoricPlanItemInstanceResponse getHistoricPlanItemInstance(String planItemInstanceId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'planItemInstanceId' is set
        if (planItemInstanceId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'planItemInstanceId' when calling getHistoricPlanItemInstance");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("planItemInstanceId", planItemInstanceId);
        String path = UriComponentsBuilder.fromPath("/cmmn-history/historic-planitem-instances/{planItemInstanceId}").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<HistoricPlanItemInstanceResponse> returnType = new ParameterizedTypeReference<HistoricPlanItemInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * List of historic plan item instances
     *
     * <p><b>200</b> - Indicates that historic planItem instances could be queried.
     * <p><b>400</b> - Indicates an parameter was passed in the wrong format. The status-message contains additional information.
     * @param planItemInstanceId The id of the historic planItem instance.
     * @param planItemInstanceName The name of the historic planItem instance.
     * @param planItemInstanceState The state of the historic planItem instance.
     * @param caseDefinitionId The id of the definition of the case were the historic planItem instance is defined.
     * @param caseInstanceId The id of the case instance were the historic planItem instance existed.
     * @param stageInstanceId The id of the stage were the historic planItem instance was contained.
     * @param elementId The id of the planItem model of the historic planItem instance.
     * @param planItemDefinitionId The id of the planItem model definition of the historic planItem instance.
     * @param planItemDefinitionType The type of planItem of the historic planItem instance.
     * @param createdBefore Return only historic planItem instances that were created before this date.
     * @param createdAfter Return only historic planItem instances that were created after this date.
     * @param lastAvailableBefore Return only historic planItem instances that were last in available before this date.
     * @param lastAvailableAfter Return only historic planItem instances that were last in available state after this date.
     * @param lastEnabledBefore Return only historic planItem instances that were last in enabled state before this date.
     * @param lastEnabledAfter Return only historic planItem instances that were last in enabled state after this date.
     * @param lastDisabledBefore Return only historic planItem instances that were last in disable state before this date.
     * @param lastDisabledAfter Return only historic planItem instances that were last in disabled state after this date.
     * @param lastStartedBefore Return only historic planItem instances that were last in active state before this date.
     * @param lastStartedAfter Return only historic planItem instances that were last in active state after this date.
     * @param lastSuspendedBefore Return only historic planItem instances that were last in suspended state before this date.
     * @param lastSuspendedAfter Return only historic planItem instances that were last in suspended state after this date.
     * @param completedBefore Return only historic planItem instances that were completed before this date.
     * @param completedAfter Return only historic planItem instances that were completed after this date.
     * @param terminatedBefore Return only historic planItem instances that were terminated before this date.
     * @param terminatedAfter Return only historic planItem instances that were terminated after this date.
     * @param occurredBefore Return only historic planItem instances that occurred before this date.
     * @param occurredAfter Return only historic planItem instances that occurred after after this date.
     * @param exitBefore Return only historic planItem instances that exit before this date.
     * @param exitAfter Return only historic planItem instances that exit after this date.
     * @param endedBefore Return only historic planItem instances that ended before this date.
     * @param endedAfter Return only historic planItem instances that ended after this date.
     * @param startUserId Return only historic planItem instances that were started by this user.
     * @param referenceId The id of process that was referenced by this historic planItem instance.
     * @param referenceType The type of reference to the process referenced by this historic planItem instance.
     * @param tenantId Only return instances with the given tenantId.
     * @param withoutTenantId If true, only returns instances without a tenantId set. If false, the withoutTenantId parameter is ignored.
     * @return DataResponseHistoricPlanItemInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseHistoricPlanItemInstanceResponse listHistoricPlanItemInstances(String planItemInstanceId, String planItemInstanceName, String planItemInstanceState, String caseDefinitionId, String caseInstanceId, String stageInstanceId, String elementId, String planItemDefinitionId, String planItemDefinitionType, String createdBefore, String createdAfter, String lastAvailableBefore, String lastAvailableAfter, String lastEnabledBefore, String lastEnabledAfter, String lastDisabledBefore, String lastDisabledAfter, String lastStartedBefore, String lastStartedAfter, String lastSuspendedBefore, String lastSuspendedAfter, String completedBefore, String completedAfter, String terminatedBefore, String terminatedAfter, String occurredBefore, String occurredAfter, String exitBefore, String exitAfter, String endedBefore, String endedAfter, OffsetDateTime startUserId, String referenceId, String referenceType, String tenantId, Boolean withoutTenantId) throws RestClientException {
        Object postBody = null;

        String path = UriComponentsBuilder.fromPath("/cmmn-history/historic-planitem-instances").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "planItemInstanceId", planItemInstanceId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "planItemInstanceName", planItemInstanceName));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "planItemInstanceState", planItemInstanceState));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "caseDefinitionId", caseDefinitionId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "caseInstanceId", caseInstanceId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "stageInstanceId", stageInstanceId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "elementId", elementId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "planItemDefinitionId", planItemDefinitionId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "planItemDefinitionType", planItemDefinitionType));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "createdBefore", createdBefore));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "createdAfter", createdAfter));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "lastAvailableBefore", lastAvailableBefore));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "lastAvailableAfter", lastAvailableAfter));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "lastEnabledBefore", lastEnabledBefore));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "lastEnabledAfter", lastEnabledAfter));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "lastDisabledBefore", lastDisabledBefore));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "lastDisabledAfter", lastDisabledAfter));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "lastStartedBefore", lastStartedBefore));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "lastStartedAfter", lastStartedAfter));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "lastSuspendedBefore", lastSuspendedBefore));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "lastSuspendedAfter", lastSuspendedAfter));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "completedBefore", completedBefore));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "completedAfter", completedAfter));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "terminatedBefore", terminatedBefore));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "terminatedAfter", terminatedAfter));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "occurredBefore", occurredBefore));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "occurredAfter", occurredAfter));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "exitBefore", exitBefore));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "exitAfter", exitAfter));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "endedBefore", endedBefore));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "endedAfter", endedAfter));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "startUserId", startUserId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "referenceId", referenceId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "referenceType", referenceType));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "tenantId", tenantId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "withoutTenantId", withoutTenantId));

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseHistoricPlanItemInstanceResponse> returnType = new ParameterizedTypeReference<DataResponseHistoricPlanItemInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Query for historic plan item instances
     * All supported JSON parameter fields allowed are exactly the same as the parameters found for getting a collection of historic plan item instances, but passed in as JSON-body arguments rather than URL-parameters to allow for more advanced querying and preventing errors with request-uri’s that are too long.
     * <p><b>200</b> - Indicates request was successful and the plan item instances are returned
     * <p><b>400</b> - Indicates an parameter was passed in the wrong format. The status-message contains additional information.
     * @param body The body parameter
     * @return DataResponseHistoricPlanItemInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseHistoricPlanItemInstanceResponse queryHistoricPlanItemInstance(HistoricPlanItemInstanceQueryRequest body) throws RestClientException {
        Object postBody = body;

        String path = UriComponentsBuilder.fromPath("/cmmn-query/historic-planitem-instances").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseHistoricPlanItemInstanceResponse> returnType = new ParameterizedTypeReference<DataResponseHistoricPlanItemInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
}
